/*  
//Compare two strings A and B, determine whether A contains all of the characters in B.
The characters in string A and B are all Upper Case letters.
Example
For A = "ABCD", B = "ABC", return true.

For A = "ABCD" B = "AABC", return false. */

package main

import "fmt"
import "strings"

var p = fmt.Printf

func wc(str string) map[string]int {
	s := strings.Split(str,"")
	m := make(map[string]int)
	for i := range s {
			m[s[i]] = m[s[i]]+1
	}
	return m
}

func contains(s1 string,s2 string) bool{
	m1 := wc(s1)
	m2 := wc(s2)

	if len(m2)>len(m1){
		return false
	}
	// 遍历子 字符串map 
	for k := range m2 {
		if m2[k] != m1[k]{
			return false
		}		
	}
	return  true
}

func main() {
	p(" %v \n",contains("ABCDf","KABCDLL"))
}

/*
   算法时间复杂度分析  设 len(str1) == n len(str2) == m
   分别遍历两个字符串切片,然后遍历 哈希表2 最坏 O(2n)
   空间复杂度   O(2(n+m))
 */